<template>
	<!-- 移动>文件夹列表 -->
	<view class="cs-file">
		<view class="cs-move-x">
			<view class="cs-move" v-for="(item,index) in file_list" :key='index'>
				<view class='cs-move-item'  @click.once='selectFile(index)' >
					<text class="iconfont iconwenjianjia1 icon_file"></text>
					<view class="ml">
						<view style="font-size: 32upx;color: #333333;">{{item.folder}}</view>
						<view style="font-size: 24upx;color: #C2C2C2;">{{item.Time}}</view>
					</view>
					<view class="cr">{{item.notes_num}}条笔记</view>
				</view>
			</view>
			<!-- 无数据 -->
			<v-none v-if='file_list.length <= 0' none_msg='文件夹列表为空'></v-none>
		</view>
	</view>
</template>
		
<script>
	import none from '../components/Base-none'; //无数据操作
	export default {
		components: {
			vNone: none
		},
		data() {
			return {
				stuId: uni.getStorageSync('userInfo').id, //个人ID
				file_list: [], // 文件夹列表,
				noteIdArr: uni.getStorageSync('noteIdArr'), // 笔记ID列表
				userInfo: uni.getStorageSync('userInfo'),
				unid: '', //笔记当前文件夹ID
			}
		},
		// 原生导航栏 > 取消
		onNavigationBarButtonTap() {
			// 取消表示进行后退
			uni.navigateBack({
				delta: 1
			})
		},
		onLoad(e) {
			this.unid = e.unid;
			uni.showLoading({
				title: '加载中...'
			})
			this.getFile();
		},
		methods: {
			// 获取文件夹笔记
			getFile() {
				var result = {usr_id: this.stuId,limit:999}
				this.$kbapi.apiPost('mobile/folder/infos',result).then(res=>{
					if(res.data.code == 200 && res.data.data.list.length > 0) {
						var list = res.data.data.list;
						list.forEach((item,key)=>{
							item.Time = item.create_time.substr(0,16);
							if(item.unid == this.unid) {
								list.splice(key,1);
							}
						})
						this.file_list = list;
					} else {
						this.file_list = [];
					}
					uni.hideLoading();
				})
			},
			// 选择移动目标文件夹
			selectFile(index) {
				var arr = uni.getStorageSync('noteIdArr');
				var folder = this.file_list[index].unid;
				arr.forEach((item,key)=>{
					var result = {
						unid: item.unid,
						folder_id: folder,
						usr_id: this.stuId,
						notes_title: item.notes_title,
						notes_content: item.notes_content,
						notes_type: item.notes_type
					}
					this.$kbapi.apiPost('mobile/notes/save',result).then(res=>{
						if(res.data.code == 200) {
							uni.showToast({
								title: '移动成功',
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 2
								})
							}, 1500)
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							})
						}
						uni.removeStorageSync('noteIdArr');
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #FAFAFA;
	}
	.cs-move {
		margin: 30upx;
	}
	.cs-move-item{
		display: flex;
		padding: 14upx 30upx;
		justify-content: space-between;
		align-items: center;
		border-bottom: 20upx solid  #FAFAFA;
		background: #FFFFFF;
		.ml {margin-left: 60upx;}
		.cr {
			white-space: nowrap;
			font-size: 28upx;
			color: #999999;
		}
	}
	
	// 图标
	.icon_file{
		position: absolute;
		left:30upx;
		font-size: 80upx;
		color: #00D5A2;
	}
</style>
